<<<<<<< HEAD
<!--
 * @Author: Xia_cc 978487464@qq.com
 * @Date: 2022-06-07 14:11:25
 * @LastEditors: Xia_cc 978487464@qq.com
 * @LastEditTime: 2022-06-10 17:27:17
 * @FilePath: \vue 小U到家\src\views\Mainlogin.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!--  -->
<template>
  <div class="login">
    <div class="head">
      <h2>小U到家站点服务台</h2>
    </div>
    <el-form label-width="0px" class="input">
      <el-form-item>
        <el-input v-model="loginUserName" placeholder="输入账号" name="user"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input type="password" v-model="loginPwd" placeholder="输入密码" name="pwd"></el-input>
      </el-form-item>
      <el-button type="info" class="loginbut" @click="Login">登录</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "Mainlogin",
  components: {},
  computed: {},
  data() {
    return {
      user: "",
      pwd: "",
      loginUserName: "",
      loginPwd: "",
    };
  },
  methods: {
    Login() {
      // console.log(this.loginUserName, this.loginPwd);
      this.$axios({
        method: "post",
        url: "/xiaoucomeshome_war/admin/login",
        data: {
          admin_phone: this.loginUserName,
          admin_pwd: this.loginPwd,
        },
        // headers: {
        //   "Content-Type": "application/json",
        //   // token: getToken(),
        // },
      })
        .then((res) => {
          if (res.data.code == 200) {
            var token = res.data.token;
            var admin_id = res.data.data.admin_id;
            var name = res.data.data.admin_name;
            window.localStorage.setItem("name", name);
            window.localStorage.setItem("token", token);
            window.localStorage.setItem("admin_id", admin_id);
            this.$router.push({
              path: "/homeView",
              // query: {
              //   admin_name: res.data.data.admin_name,
              // },
            });
          }
          // this.$router.push("/homeView");
          // console.log(res.data);
        })
        .catch((err) => {
          console.log("重新登陆");
        });
    },
  },
};
</script>

<style lang="less" scoped>
.login {
  width: 100%;
  margin: auto;
  text-align: center;

  .input {
    width: 20%;
    margin: 140px 0 0 40%;
  }

  .loginbut {
    width: 100%;
  }
  .head {
    // position: absolute;
    // top: 0;
    // right: 0;
    width: 100%;
    height: 120px;
    background-color: rgba(6, 6, 6, 0.1);
    h2 {
      line-height: 120px;
      margin: 0;
      color: #7f7f7f;
    }
  }
}
</style>
=======
<!--
 * @Author: Xia_cc 978487464@qq.com
 * @Date: 2022-06-07 14:11:25
 * @LastEditors: Xia_cc 978487464@qq.com
 * @LastEditTime: 2022-06-10 17:27:17
 * @FilePath: \vue 小U到家\src\views\Mainlogin.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!--  -->
<template>
  <div class="login">
    <div class="head">
      <h2>小U到家站点服务台</h2>
    </div>
    <el-form label-width="0px" class="input">
      <el-form-item>
        <el-input v-model="loginUserName" placeholder="输入账号" name="user"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input type="password" v-model="loginPwd" placeholder="输入密码" name="pwd"></el-input>
      </el-form-item>
      <el-button type="info" class="loginbut" @click="Login">登录</el-button>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "Mainlogin",
  components: {},
  computed: {},
  data() {
    return {
      user: "",
      pwd: "",
      loginUserName: "",
      loginPwd: "",
    };
  },
  methods: {
    Login() {
      // console.log(this.loginUserName, this.loginPwd);
      this.$axios({
        method: "post",
        url: "/xiaoucomeshome_war/admin/login",
        data: {
          admin_phone: this.loginUserName,
          admin_pwd: this.loginPwd,
        },
        // headers: {
        //   "Content-Type": "application/json",
        //   // token: getToken(),
        // },
      })
        .then((res) => {
          if (res.data.code == 200) {
            var token = res.data.token;
            var admin_id = res.data.data.admin_id;
            var name = res.data.data.admin_name;
            window.localStorage.setItem("name", name);
            window.localStorage.setItem("token", token);
            window.localStorage.setItem("admin_id", admin_id);
            this.$router.push({
              path: "/homeView",
              // query: {
              //   admin_name: res.data.data.admin_name,
              // },
            });
          }
          // this.$router.push("/homeView");
          // console.log(res.data);
        })
        .catch((err) => {
          console.log("重新登陆");
        });
    },
  },
};
</script>

<style lang="less" scoped>
.login {
  width: 100%;
  margin: auto;
  text-align: center;

  .input {
    width: 20%;
    margin: 140px 0 0 40%;
  }

  .loginbut {
    width: 100%;
  }
  .head {
    // position: absolute;
    // top: 0;
    // right: 0;
    width: 100%;
    height: 120px;
    background-color: rgba(6, 6, 6, 0.1);
    h2 {
      line-height: 120px;
      margin: 0;
      color: #7f7f7f;
    }
  }
}
</style>
>>>>>>> ae27e4fe2d4f939d0b0ee2bfa506b9e3269c53cb
